package com.yupi.project.aop;

import com.test.springbootjwtautoconfigura.JwtUtils;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@Aspect
@Component
public class LoginJWTIntercepetor {



    @Resource
    private HttpServletRequest request;


    @Around("execution(* com.yupi.project.controller.*.*(..))")
    public Object JwtTest(ProceedingJoinPoint point) throws Throwable {
        final String uri = request.getRequestURI();
        if(uri.contains("login")){
            return  point.proceed();
        }
        String jwt = request.getHeader("token");
        System.out.println(request);
        System.out.println("JWT令牌："+ jwt);
        final Claims claims = JwtUtils.parseJWT(jwt);
        return point.proceed();
    }
}
